#include "ZigbeeWidget.h"
#include <QApplication>
#include <QTextCodec>
#include <QtCore/QTextStream>
#include <QtCore/QFile>
#include <QtCore/QIODevice>

/*********************************
 * 设置中文显示支持utf8
 *********************************/
_S32 setZhFormat()
{
    QTextCodec *codec=QTextCodec::codecForName("utf-8");
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);

    return SUCCESS;
}

void customMessageHandler(QtMsgType type, const char *msg)
{
        QString txt;
        switch (type) {
        //调试信息提示
        case QtDebugMsg:
                txt = QString("Debug: %1").arg(msg);
                break;

        //一般的warning提示
        case QtWarningMsg:
                txt = QString("Warning: %1").arg(msg);
        break;
        //严重错误提示
        case QtCriticalMsg:
                txt = QString("Critical: %1").arg(msg);
        break;
        //致命错误提示
        case QtFatalMsg:
                txt = QString("Fatal: %1").arg(msg);
                abort();
        }

        QFile outFile("C:/Users/Administrator/Desktop/trbc2/debuglog.txt");
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
        QTextStream ts(&outFile);
        ts << txt << endl;
}

int main(int argc, char *argv[])
{
    setZhFormat();
    QApplication a(argc, argv);
    Widget w;

    //先注册自己的MsgHandler
    //qInstallMsgHandler(customMessageHandler);

    w.show();
    
    return a.exec();
}
